package com.dt76.smallloanfrontenduser.controller;

import com.dt76.smallloanfrontenduser.pojo.xiaohao.BorrowOrder;
import com.dt76.smallloanfrontenduser.pojo.xiaohao.HLoanProducts;
import com.dt76.smallloanfrontenduser.pojo.xiaohao.HxLoanType;
import com.dt76.smallloanfrontenduser.pojo.xiaohao.Information;
import com.dt76.smallloanfrontenduser.remote.xiaohao.HXLoanTypeRemote;
import com.dt76.smallloanfrontenduser.remote.xiaohao.InformationRemote;
import com.dt76.smallloanfrontenduser.remote.xiaohao.LoanProductRemote;
import com.dt76.smallloanfrontenduser.remote.xiaohao.XBorrowOrderRemote;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class IndexController {

    @Resource
    private XBorrowOrderRemote xBorrowOrderRemote;
    @Resource
    private LoanProductRemote loanProductRemote;
    @Resource
    private HXLoanTypeRemote hxLoanTypeRemote;
    @Resource
    private InformationRemote informationRemote;

    @RequestMapping("/index")
    public String index(Model model){
        List<Information> information = informationRemote.qryAll();
        model.addAttribute("information",information.get(0));
        return "index";
    }
    @RequestMapping("/regist")
    public String regist(){
        return "regist";
    }
    @RequestMapping("/admin")
    public String admin(){
        return "admin";
    }
    @RequestMapping("/main")
    public String main(Model model,String userId) {
        List<BorrowOrder> borrowOrders = xBorrowOrderRemote.qryAllBorrowOrderByUId(Integer.parseInt(userId));
        model.addAttribute("borrowOrders",borrowOrders);
        System.out.println(borrowOrders.size());
        return "main";
    }

    @RequestMapping("/order")
    public String order(Model model) {
        List<HLoanProducts> hLoanProducts = loanProductRemote.qryAllLoanProducts();
        List<HxLoanType> hxLoanTypes = hxLoanTypeRemote.qryAllLoanType();
        model.addAttribute("hLoanProducts",hLoanProducts);
        model.addAttribute("hxLoanTypes",hxLoanTypes);
        return "order";
    }

    @RequestMapping("/mainRep")
    public String mainRep(Model model,String userId) {
        model.addAttribute("userId",userId);
        return "repayment";
    }
}
